package com.waves.core.config;

import com.waves.core.handle.BlackInterceptor;
import com.waves.core.handle.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 自定义配置springmvc：添加拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private TokenInterceptor tokenInterceptor;
    @Resource
    private BlackInterceptor blackInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截以/xxx开头的请求
        // token拦截、黑名单拦截
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/userApi/**")
                .addPathPatterns("/task/**")
                .addPathPatterns("/taskComment/**")
                .addPathPatterns("/messageRecord/**");
        registry.addInterceptor(blackInterceptor)
                .addPathPatterns("/userApi/**")
                .addPathPatterns("/task/**")
                .addPathPatterns("/taskComment/**")
                .addPathPatterns("/messageRecord/**")
                ;
    }
}